package com.hello.booksale.dao;

import com.hello.booksale.entity.BookEntity;
import com.hello.booksale.entity.CartEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

public interface CartDao {

    @Select("SELECT * FROM cart WHERE user_name=#{userName}")
    List<CartEntity> selectCartByUserName(@Param("userName") String userName);

    @Insert("INSERT INTO cart (user_name,book_id,book_num,book_url,book_name,book_detail,book_author,book_price,cart_time) VALUES (#{userName},#{bookId},#{bookNum},#{bookUrl},#{bookName}" +
            ",#{bookDetail},#{bookAuthor},#{bookPrice},#{cartTime})")
    void insertCart(CartEntity cartEntity);

    @Select("SELECT * FROM book WHERE book.book_id=#{bookId}")
    BookEntity selectBookByCartBookId(@Param("bookId") int bookId);



    @Delete("DELETE FROM cart WHERE book_id=#{bookId} AND cart_time=#{cartTime}")
    void deleteCartByBookId(@Param("bookId") int bookId,@Param("cartTime") String cartTime);

    @Delete("DELETE FROM cart WHERE user_name=#{userName} ")
    void deleteCartBYUserName(@Param("userName") String userName);
}